/// 版本数据模型 - Version Data Model
/// 表示 Prompt 的一个历史版本
class VersionModel {
  /// 版本唯一标识符 - Version unique identifier
  final String id;
  /// 所属 Prompt ID - Parent prompt ID
  final String promptId;
  /// 版本号 - Version number
  final int versionNumber;
  /// 版本标题 - Version title
  final String title;
  /// 版本内容 - Version content
  final String content;
  /// 版本标签 - Version tags
  final List<String> tags;
  /// 版本分类 - Version category
  final String category;
  /// 版本描述 - Version description
  final String description;
  /// 版本创建时间 - Version created time
  final DateTime createdAt;
  /// 变更日志 - Change log
  final String changeLog;
  /// 版本文件路径 - Version file path
  final String filePath;
  /// 版本元数据 - Version metadata
  final Map<String, dynamic> metadata;

  VersionModel({
    required this.id,
    required this.promptId,
    required this.versionNumber,
    required this.title,
    required this.content,
    this.tags = const [],
    this.category = '',
    this.description = '',
    required this.createdAt,
    this.changeLog = '',
    required this.filePath,
    this.metadata = const {},
  });

  /// 从 JSON 创建 VersionModel - Create VersionModel from JSON
  VersionModel.fromJson(Map<String, dynamic> json)
      : id = json['id'] as String,
        promptId = json['promptId'] as String,
        versionNumber = json['versionNumber'] as int,
        title = json['title'] as String,
        content = json['content'] as String,
        tags = List<String>.from(json['tags'] ?? []),
        category = json['category'] as String? ?? '',
        description = json['description'] as String? ?? '',
        createdAt = DateTime.parse(json['createdAt'] as String),
        changeLog = json['changeLog'] as String? ?? '',
        filePath = json['filePath'] as String,
        metadata = Map<String, dynamic>.from(json['metadata'] ?? {});

  /// 转换为 JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'promptId': promptId,
      'versionNumber': versionNumber,
      'title': title,
      'content': content,
      'tags': tags,
      'category': category,
      'description': description,
      'createdAt': createdAt.toIso8601String(),
      'changeLog': changeLog,
      'filePath': filePath,
      'metadata': metadata,
    };
  }
}
